package cn.wjh.business.controller;

import cn.wjh.business.domain.Focus;
import cn.wjh.business.service.IFocusService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 关注Controller
 *
 * @author jiraWu
 * @date 2023-10-22
 */
@RestController
@RequestMapping("/business/focus")
public class FocusController extends BaseController {
	@Resource
	private IFocusService focusService;

	@GetMapping("/list")
//	@PreAuthorize("@ss.hasPermi('business:focus:list')")
	public TableDataInfo list(Focus focus) {
		startPage();
		List<Focus> list = focusService.selectFocusList(focus);
		return getDataTable(list);
	}

	/**
	 * 查询关注列表
	 */
	@GetMapping("/my")
	public TableDataInfo myFocus(Focus focus) {
		startPage();
		List<Focus> list = focusService.myFocus(focus);
		return getDataTable(list);
	}

	/**
	 * 导出关注列表
	 */
//	@PreAuthorize("@ss.hasPermi('business:focus:export')")
	@Log(title = "关注", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, Focus focus) {
		List<Focus> list = focusService.selectFocusList(focus);
		ExcelUtil<Focus> util = new ExcelUtil<Focus>(Focus.class);
		util.exportExcel(response, list, "关注数据");
	}

	/**
	 * 获取关注详细信息
	 */
//	@PreAuthorize("@ss.hasPermi('business:focus:query')")
	@GetMapping(value = "/{focusId}")
	public AjaxResult getInfo(@PathVariable("focusId") Long focusId) {
		return success(focusService.selectFocusByFocusId(focusId));
	}

	/**
	 * 新增关注
	 */
//	@PreAuthorize("@ss.hasPermi('business:focus:add')")
	@Log(title = "关注", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody Focus focus) {
		return toAjax(focusService.insertFocus(focus));
	}

	/**
	 * 修改关注
	 */
//	@PreAuthorize("@ss.hasPermi('business:focus:edit')")
	@Log(title = "关注", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody Focus focus) {
		return toAjax(focusService.updateFocus(focus));
	}

	/**
	 * 删除关注
	 */
//	@PreAuthorize("@ss.hasPermi('business:focus:remove')")
	@Log(title = "关注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{focusIds}")
	public AjaxResult remove(@PathVariable Long[] focusIds) {
		return toAjax(focusService.deleteFocusByFocusIds(focusIds));
	}

//	@PreAuthorize("@ss.hasPermi('business:focus:isFocus')")
	@GetMapping("/status/{receiveId}")
	public AjaxResult isFocus(@PathVariable Long receiveId) {
		AjaxResult result = success();
		result.put(AjaxResult.DATA_TAG, focusService.isFocus(receiveId));
		return result;
	}


}
